<template>
<div class="login_container">
    <div class="login_box">

        <div class="avater_box">
            <img src="https://cn.vuejs.org/images/logo.svg" alt="">
        </div>
        <el-form ref='loginFromRef' :rules='loginFormRules' label-width="00px" class="login_form" :model="loginForm">
            <!-- 用户名 -->
            <el-form-item prop="username">
                <el-input prefix-icon="el-icon-s-custom" v-model="loginForm.username"></el-input>
            </el-form-item>
            <!-- 密码 -->
             <el-form-item prop="password">
                <el-input prefix-icon="el-icon-lock" v-model="loginForm.password" type="password"></el-input>
            </el-form-item>
            <!-- 按钮区域 -->
             <el-form-item class="btns">
               <el-button type="primary" @click="login" :plain="true">登录</el-button>
               <el-button type="info" @click="resetLoginForm">重置</el-button>
            </el-form-item>
        </el-form>

    </div>
</div>
</template>
<script>
export default {
  data () {
    return {
      loginForm: {
        username: '',
        password: '2331'
      },
      //   表单验证
      loginFormRules: {
        //   用户名是否合法
        username: [
          { required: true, message: '请输入活动名称', trigger: 'blur' },
          { min: 3, max: 5, message: '长度在 3 到 5 个字符', trigger: 'blur' }
        ],
        // 验证密码
        password: [
          { required: true, message: '请输入密码', trigger: 'blur' },
          { min: 3, max: 5, message: '长度在 3 到 5 个字符', trigger: 'blur' }
        ]
      }
    }
  },
  methods: {
    //   点击重置
    resetLoginForm () {
      // 重置数据
      this.$refs.loginFromRef.resetFields()
    },
    login () {
      this.$refs.loginFromRef.validate(valid => {
        if (!valid) {
          return console.log('请输入用户名与密码')
        }
        // 往后端发数据
        // 提示成功或者失败
        this.$message({
          message: '登录成功',
          type: 'success'
        })
        // 模拟一个token,其实是后端返回的
        const tokendata = 1231121
        // 保持token
        window.sessionStorage.setItem('token', tokendata)
        // 登录成功后跳转
        this.$router.push('/home')
      })
    }
    // open2 () {

    // }

  }
}
</script>
<style scoped>
.login_container{
    background-color: #2b4b6b;
    height:100%;
}
.login_box{
    width:450px;
    height: 300px;
    background: #fff;
    position: absolute;
    left: 50%;
    top: 50%;
    transform:translate(-50%,-50%);
    border-radius: 3px;
}
.login_box .avater_box{
    height: 130px;
    width: 130px;
    border-radius: 50%;
    border:1px solid #eee;
    padding:10px;
    box-shadow: 0 0 10px #ddd;
    position: absolute;
    left: 50%;
    transform: translate(-50%,-50%);
    background:#fff;

}
.login_box .avater_box img{
    height: 130px;
    width: 130px;
    border-radius: 50%;
    background: #eee;

}
.login_form{
position: absolute;
bottom:0;
padding: 0 20px;
width:100%;
box-sizing: border-box;
}
.btns{
    display: flex;
    justify-content: flex-end;

}
</style>
